package com.sunose.agfmk;


import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import com.sunose.agfmk.constant.Constant;
import com.sunose.agfmk.view.GameView;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.ActivityCompat;

import com.sunose.agfmk.utils.GameAlertDialog;

public class MainActivity extends FragmentActivity {
  public final static String tag=Constant.TAG_PREFIX+"_mainactivity";
   public MainActivity parent=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(tag,this.getClass().getName()+" oncreate");
        super.onCreate(savedInstanceState);
        parent=this;
        setContentView(R.layout.activity_main);

    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(tag,this.getClass().getName()+" onResume");

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    public void buttonRouter(View view) {
       int btid=view.getId();

        switch(btid)
        {
            case R.id.bt_rotate: changeActivity("com.sunose.agfmk.examples.RotateActivity");break;
            case R.id.bt_xor: changeActivity("com.sunose.agfmk.examples.XorActivity");break;
            case R.id.bt_movie:alert("movie");break;
            case R.id.bt_transpant:alert("transpant");break;
            case R.id.bt_quit:alert("Quite App!");this.finish();
        }

    }
   public void changeActivity(String classActivity)
   {
       try
       {
       Intent intent = new Intent(this, this.getClass().getClassLoader().loadClass(classActivity));
       startActivity(intent);
       }catch (Exception e)
       {
         alert(e.getMessage());
       }
   }
   public void alert(String msg)
   {
       Log.d(tag,"alert at "+new java.util.Date());
       DialogFragment newFragment = GameAlertDialog.newInstance(msg);
//    newFragment.show(this.getFragmentManager(),"dialog");
       newFragment.show(this.getSupportFragmentManager(),"dialog");
//

        }
}
